package LeetCode.month02.day36;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class No12 {

    public String intToRoman(int num,int a) {
        // 1. 创建数值和符号的映射关系，并按从大到小排序
        int[] values =    {1000, 900,  500, 400,  100, 90,   50,  40,   10,  9,    5,   4,    1};
        String[] symbols = {"M",  "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

        StringBuilder sb = new StringBuilder();

        // 2. 遍历这个映射关系
        for (int i = 0; i < values.length && num > 0; i++) {
            // 3. 使用 while 循环处理当前面值
            //    这会处理像 300 (CCC) 或 30 (XXX) 这样的情况
            while (num >= values[i]) {
                // 4. 追加符号并减去对应的值
                sb.append(symbols[i]);
                num -= values[i];
            }
        }

        return sb.toString();
    }
    public String intToRoman(int num) {
        Map<Integer,String> map1 = new HashMap<>();
        List<Map<Integer,String>> list = new ArrayList<>();
        map1.put(0,"");
        map1.put(1,"I");
        map1.put(2,"II");
        map1.put(3,"III");
        map1.put(4,"IV");
        map1.put(5,"V");
        map1.put(6,"VI");
        map1.put(7,"VII");
        map1.put(8,"VIII");
        map1.put(9,"IX");
        list.add(map1);
        map1 = new HashMap<>();
        map1.put(0,"");
        map1.put(1,"X");
        map1.put(2,"XX");
        map1.put(3,"XXX");
        map1.put(4,"XL");
        map1.put(5,"L");
        map1.put(6,"LX");
        map1.put(7,"LXX");
        map1.put(8,"LXXX");
        map1.put(9,"XC");
        list.add(map1);
        map1 = new HashMap<>();
        map1.put(0,"");
        map1.put(1,"C");
        map1.put(2,"CC");
        map1.put(3,"CCC");
        map1.put(4,"CD");
        map1.put(5,"D");
        map1.put(6,"DC");
        map1.put(7,"DCC");
        map1.put(8,"DCCC");
        map1.put(9,"CM");
        list.add(map1);
        map1 = new HashMap<>();
        map1.put(1,"M");
        map1.put(2,"MM");
        map1.put(3,"MMM");
        list.add(map1);
        String s = num+"";
        int n = s.length();
        char[] c = s.toCharArray();
        String res = "";
        for (int i = n - 1; i >= 0; i--) {
            int index = n-1-i;
            res=list.get(index).get(c[i]-'0')+res;
        }
        return res;
    }
}
